* **************************************************************************** *
* Sierra Leone - Social Signaling and Childhood Immunization
* Table: Description of Study Sample and Endline Survey
* **************************************************************************** *
/*
** Purpose:  Create Balance Table on Endline Survey Sample


*/
* **************************************************************************** *
* **************************************************************************** *


	use  "${Replicate_SocialSignals_dtaInter}/Balance_StudyEndlineSample.dta", clear



	* Drop existing matrices
	cap mat drop _all


	* --------------------------------------------------------------------------
	* Run balance in 2 steps: (1) ttest differences, (2) p-values

	* Panel A: Characteristics of the endline sample
	local   MotherVars    = " interview_mother_end mother_age_end married_end tribe2_end tribe3_end livedincom_end "
	local   EducationVars = " edu1_end edu2_end edu3_end "
	local   AssetVars     = " farm_end mobile_phone_end floor_end roof_end "
	local   ChildVars     = " birth_order_end age_pikin_month_end "

	* Panel B: First- and Second-Order Beliefs
	local   BeliefsIntro  = " caregiver_given caregiver_known "
	local   BeliefsVars   = " mother_age_w01_second edu2_second edu3_second farm_second relate_second birth_order_second "

	* Set variables locals
	local   treatVar      = " intervention_arm "
	local   strataVar     = " strata "
	local   clusterVar    = " clinic_code "
	local   covariates    = " anc2 anc3 anc4 "



	* **************************************************************************** *
	* 1.) Panel A: Characteristics of the endline sample
	* **************************************************************************** *
	* Mother characteristics

	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  `MotherVars',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values

	preserve

		#d ;
		iebaltab   `MotherVars',
		vce(cluster `clusterVar')
			grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
	
	restore



	* ---------------------------------------------------------------------------- *
	* Merge ttest differences & p-values
	* ---------------------------------------------------------------------------- *

	preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 =  "Observations"         if v1 == "N"
		replace v1 =  "Clinics"              if v1 == "Clusters"

		drop if v1 == "Clinics"

		local    mother_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/mother_balance_`mother_fileNum'.tex") ///
		replace tex nohead noauto

	restore



	* **************************************************************************** *
	* 2.) Education Variables
	* **************************************************************************** *


	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  `EducationVars',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values
	preserve

		#d ;
		iebaltab   `EducationVars',
		vce(cluster `clusterVar')
		 grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
		
	restore


	* ---------------------------------------------------------------------------- *
	* Merge ttest differences & p-values
	* ---------------------------------------------------------------------------- *

	preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 = "Observations"         if v1 == "N"
		replace v1 = "Clinics"              if v1 == "Clusters"


		local    education_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/education_balance_`education_fileNum'.tex") ///
		replace tex nohead noauto

	restore



	* **************************************************************************** *
	* 3.) Asset Variables
	* **************************************************************************** *


	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  `AssetVars',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values
	preserve

		#d ;
		iebaltab   `AssetVars',
		vce(cluster `clusterVar')
		 grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
		
	restore


	* ---------------------------------------------------------------------------- *
	* Merge ttest differences & p-values
	* ---------------------------------------------------------------------------- *

	preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 = "Observations"         if v1 == "N"
		replace v1 = "Clinics"              if v1 == "Clusters"


		local    assets_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/assets_balance_`assets_fileNum'.tex") ///
		replace tex nohead noauto

	restore




	* **************************************************************************** *
	* 4.) Child Characteristics:
	* **************************************************************************** *


	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  ///
		`ChildVars',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values
	preserve

		#d ;
		iebaltab    ///
		`ChildVars',
		vce(cluster `clusterVar')
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
		
	restore


	* ---------------------------------------------------------------------------- *
	* Merge ttest differences & p-values
	* ---------------------------------------------------------------------------- *

	preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 = "Observations"         if v1 == "N"
		replace v1 = "Clinics"              if v1 == "Clusters"


		local    child_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/child_balance_`child_fileNum'.tex") ///
		replace tex nohead noauto

	restore




	* **************************************************************************** *
	* 5.) Beliefs Intro:
	* **************************************************************************** *


	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  ///
		`BeliefsIntro',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values
	preserve

		#d ;
		iebaltab    ///
		`BeliefsIntro',
		vce(cluster `clusterVar')
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
		restore


		* ---------------------------------------------------------------------------- *
		* Merge ttest differences & p-values
		* ---------------------------------------------------------------------------- *

		preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 = "Observations"         if v1 == "N"
		replace v1 = "Clinics"              if v1 == "Clusters"


		local    beliefsintro_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/beliefsintro_balance_`beliefsintro_fileNum'.tex") ///
		replace tex nohead noauto

	restore




	* **************************************************************************** *
	* 6.) Beliefs Variables :
	* **************************************************************************** *



	* ---------------------------------------------------------------------------- *
	* Compute ttest  mean differences
	* ---------------------------------------------------------------------------- *

	* (1) ttest mean differences

	preserve

		iebaltab  ///
		`BeliefsVars',  ///
		vce(cluster `clusterVar') ///
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4) ///
		fmissok feqtest pftest covarmissok    fnoobs   ${BalStars} ///
		rowvarlabels onerow ///
		tblnonote ///
		browse ///
		replace

		drop in 1/3

		gen     count = _n

		* Temporary save the table output
		tempfile  ttest_diff
		save   	 `ttest_diff'

	restore


	* ---------------------------------------------------------------------------- *
	* Compute ttest p-values
	* ---------------------------------------------------------------------------- *

	*  p-values
	preserve

		#d ;
		iebaltab    ///
		`BeliefsVars',
		vce(cluster `clusterVar')
		grpvar(`treatVar') fixedeffect(`strataVar') covariates(`covariates') ///
		grplabels(1 Control @ 2 Uninformative @ 3 Signal at 4  @ 4 Signal at 5 ) order(1 2 3 4)
		fmissok feqtest pboth covarmissok   fnoobs   ${BalStars}
		rowvarlabels onerow
		tblnonote
		browse
		replace
		;
		#d	cr

		drop in 1/3
		gen     count = _n

		drop    v2-v5

		foreach    variable of numlist 6(1)11 {
		replace v`variable' = "[" + v`variable' + "]"     if v`variable' !=""
		}
		replace count = count +1

		drop if v1 == ""

		* Temporary save the table output
		tempfile  ttest_pvals
		save   	 `ttest_pvals'
	
	restore


	* ---------------------------------------------------------------------------- *
	* Merge ttest differences & p-values
	* ---------------------------------------------------------------------------- *

	preserve

		use `ttest_diff', clear

		merge 1:1 count using `ttest_pvals', gen(Merge) keepusing(v6-v11) update


		* Compute Number of Observations and Clinics below each test:
		foreach column in 1 2 3 4 {
		local   col_1 = `column'+1
		gen     n`column' = v`col_1'           if inlist(v1,"N","Clusters")
		}

		foreach column in 1 2 3 4  {
		destring n`column', replace
		}

		* Generate new columns for difference calculations:
		foreach column of numlist 6(1)11 {
		gen      n`column' = .
		}

		* Compute the new N's:
		replace  n6  = n1+n2
		replace  n7  = n1+n3
		replace  n8  = n1+n4
		replace  n9  = n2+n3
		replace  n10 = n2+n4
		replace  n11 = n3+n4

		* String and replace:
		foreach column of numlist 6(1)11 {
		tostring n`column', replace
		}

		foreach column of numlist 6(1)11 {
		replace v`column' = n`column'               if n`column' !="." & v`column' ==""
		}

		foreach column of numlist 2(1)5 {
		replace v`column' = ""                      if v`column' !="" & inlist(v1,"N","Clusters")
		}

		* Keep only the Control Group Mean:
		drop v3-v5
		drop n1-n11

		drop count Merge

		replace v1 = "Observations"         if v1 == "N"
		replace v1 = "Clinics"              if v1 == "Clusters"


		local    beliefs_fileNum = 0

		dataout, save("${Replicate_SocialSignals_ATables}/beliefs_balance_`beliefs_fileNum'.tex") ///
		replace tex nohead noauto

	restore




	* **************************************************************************** *
	* Prepare Final Table
	* **************************************************************************** *

	cap  file close _all


	local BalanceTables =  " mother education assets child beliefsintro beliefs "

	foreach level of local BalanceTables {

		* Remove lines from `dataout` export
		foreach lineToRemove in "\BSdocumentclass[]{article}"			///
			"\BSsetlength{\BSpdfpagewidth}{8.5in}" 	///
			"\BSsetlength{\BSpdfpageheight}{11in}"  ///
			"\BSbegin{document}" 				       	///
			"\BSend{document}" 					     	///
			"\BSbegin{tabular}{lcccccccc}"			///
			"Variable"								///
			"\BShline"								///
			"\BSend{tabular}"						{

			filefilter "${Replicate_SocialSignals_ATables}/`level'_balance_``level'_fileNum'.tex"      ///
			"${Replicate_SocialSignals_ATables}/`level'_balance_`=``level'_fileNum'+1'.tex" ///
			, from("`lineToRemove'") to("") replace
			erase	     "${Replicate_SocialSignals_ATables}/`level'_balance_``level'_fileNum'.tex"

			local `level'_fileNum = ``level'_fileNum' + 1
		}

		* Add incipit and end of LaTeX table
		*(to be directly input in TeX document) without further formatting
		file open  `level'File													///
		using "${Replicate_SocialSignals_ATables}/`level'_balance_``level'_fileNum'.tex"               ///
		, text read

		* Loop over lines of the original TeX file and save everything in a local
		local 	   `level'File ""
		file read  `level'File line
		while r(eof) == 0 {
		local 	  `level'File  " ``level'File' `line' "
		file read `level'File line
	
	}
		file close `level'File

		* Erase original file
		erase "${Replicate_SocialSignals_ATables}/`level'_balance_``level'_fileNum'.tex"

	}


	dis "`motherFile'"
	dis "`educationFile'"
	dis "`assetsFile'"
	dis "`childFile'"
	dis "`beliefsintroFile'"
	dis "`beliefsFile'"



	* Make final table
	file  open finalFile using "${Replicate_SocialSignals_ATables}/baltab_endlinesample.tex"	///
	, text write replace

	#d	;

	file write finalFile
	"                                      & \multicolumn{1}{c}{(1)}                 & \multicolumn{1}{c}{(2)}               & \multicolumn{1}{c}{(3)}               & \multicolumn{1}{c}{(4)}                & \multicolumn{1}{c}{(5)}                 & \multicolumn{1}{c}{(6)}               & \multicolumn{1}{c}{(7)}  & \multicolumn{1}{c}{(8)}  \\"    _n      ///
	"                                       &                                        & \multicolumn{6}{c}{\textbf{t-test differences}}    & \multicolumn{1}{c}{}  \\"    _n   ///
	"                                       & \multicolumn{1}{c}{\textbf{Control}}   & \multicolumn{6}{c}{\textbf{[p-value]}}             & \multicolumn{1}{c}{}  \\"    _n   ///
	"\multicolumn{1}{l}{\textbf{Variable}}  & \multicolumn{1}{c}{\textbf{Mean/(SE)}} & \multicolumn{1}{c}{\textbf{(C)-(UI)}} & \multicolumn{1}{c}{\textbf{(C)-(S4)}} &  \multicolumn{1}{c}{\textbf{(C)-(S5)}} & \multicolumn{1}{c}{\textbf{(UI)-(S4)}} & \multicolumn{1}{c}{\textbf{(UI)-(S5)}} & \multicolumn{1}{c}{\textbf{(S4)-(S5)}} & \multicolumn{1}{c}{\textbf{F-Test}} \\ \hline \\[-2ex]"    _n    ///
	"\multicolumn{9}{l}{\textbf{\textit{Panel A: Endline characteristics}}}                \\ [0.5ex] " _n
	"\addlinespace[0.75ex] `motherFile' 																				           \\ [-2ex]  " _n
	"\multicolumn{9}{l}{\textbf{\textit{ Education}}}				                               \\ [0.5ex] " _n
	" `educationFile' 																						                         \\ [-2ex]  " _n
	"\multicolumn{9}{l}{\textbf{\textit{ Occupation \& Assets}}}				                   \\ [0.5ex] " _n
	" `assetsFile' 																						                             \\ [-2ex]  " _n
	"\multicolumn{9}{l}{\textbf{\textit{ Child characteristics}}}				                   \\ [0.5ex] " _n
	" `childFile' 																						                             \\ [-2ex]  " _n
	"\multicolumn{9}{l}{\textbf{\textit{Panel B: First- and Second-Order Beliefs}}}				 \\ [0.5ex] " _n
	"\addlinespace[0.75ex] `beliefsintroFile' 													                      [-2ex]  " _n
	"\multicolumn{9}{l}{\textbf{\textit{Set of controls: Sample 3.5-12 months}}}           \\ [0.5ex] " _n
	"\addlinespace[0.75ex] `beliefsFile' 										                                  [-2ex]  " _n
	"																													               \hline \hline \\ [-2ex]  "
	;
	#d	cr

	file close finalFile



* **************************************************************************** *
* End of the Dofile !!!
* **************************************************************************** *
